{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
    .col-sm-1 {
        width: 20%;
    !important;
    }
</style>

<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">

        <div class="ch-row ch-info-form">
            <p class="flex1">产品分类：</p>
            <div class="flex2">
                <select  class="chan form-control" name="chan">
                    <option value="0" <?php if($data["fen"]==0){?> selected="selected" <?php }?>>套餐</option>
                    <option value="1" <?php if($data["fen"]==1){?> selected="selected" <?php }?>>维修与安装</option>
                    <option value="2" <?php if($data["fen"]==2){?> selected="selected" <?php }?>>其他</option>
                </select>&nbsp
            </div>
        </div>
        <div class="row  cp">

        </div>
        <div class="ch-row ch-info-form cl ll" >
            <p class="flex1">单价：</p>
            <div class="flex2  ch-row ch-info-form-price" >
                <span class="input-group-addon">$</span>
                <input type="text" class="form-control dan1" name="un_Price" readonly="readonly"
                       style=" background-color: rgb(235, 235, 228); " value="{$data['un_Price']}">


            </div>

        </div>
        <div class="ch-row ch-info-form cl">
            <p class="flex1">方量：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <input type="text" name="square" class="fang" style="width: 55%" value="{$data['square']}">
                <input type="text" readonly="readonly" name="company" class="companys" style="width: 15%; border-left: 1px solid #ddd; text-align: right;" value="{$data['company']}" >
                <span  class="wei" style="width: 30%; border: none; padding-left: 5px;"> / 单位</span>
            </div>
        </div>
        <!--<div class="ch-row ch-info-form cl">-->
            <!--<p class="flex1">方量：</p>-->
            <!--<div class="flex2 ch-row ch-info-form-price" >-->
                <!--<input type="text" name="square" class="form-control fang"  value="{$data['square']}">&nbsp;-->
                <!--<input type="text" readonly="readonly" name="company" class="companys form-control"  value="{$data['company']}" style="width: 15%; border-left: 1px solid #ddd; text-align: right;"  >-->

                <!--<span class="wei"></span>-->
            <!--</div>-->
        <!--</div>-->
        <input type="hidden" name="capital_id" value="{$data['capital_id']}">
        <input type="hidden" name="order_id" value="{$data['ordesr_id']}">
        <input type="hidden" value="{$through_id}" name="through_id">
        <div class="ch-row ch-info-form cl">
            <p class="flex1">质保：</p>
            <div class="flex2">
                <input type="radio" value="0" name="zhi" class="zhi" <?php if($data["zhi"]==0){?> checked="checked" <?php }?> >否 &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" value="1" name="zhi" class="zhi" <?php if($data["zhi"]==1){?> checked="checked" <?php }?>>是
            </div>
        </div>
        <div class="ch-row ch-info-form ">
            <p class="flex1">总价：</p>
            <div class="flex2 ch-row ch-info-form-price" >
                <span>$</span>
                <input type="text" class="jia "  name="to_price" readonly="readonly"  value="{$data['to_price']}">


            </div>

        </div>

        <div class="ch-row ch-info-form">
            <button class="btn btn-primary radius" type="button"><i
                    class="Hui-iconfont">&#xe632;</i> 提交
            </button>
        </div>

    </form>
</article>
{include file="public/footer"}
<script>
    s();
    $('.chan').bind("change", function () {
        $('.shan').remove();
        s();
    });
    function s(){
        var cha = $(".chan option:selected").val();
        if (cha == 0) {
            var html =`
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">套餐选择：</p>
                    <div class="flex2">
                        <select name="class_a" class="class_a2 form-control">
                            {volist name="gs" id="v"}
                            <option value="{$v.product_id}"  <?php if($data["class_a"]==$v["product_title"]){?> selected="selected" <?php }?>>{$v.product_title}</option>\n
                            {/volist}
                        </select>
                        <select name="class_b" class="class_b form-control">
                            {volist name="gs1" id="v"}
                            <option value="{$v.product_id}"  <?php if($data["class_b"]==$v["product_title"]){?> selected="selected" <?php }?>>{$v.product_title}</option>\n
                            {/volist}
                        </select>
                    </div>
                </div>`

            $(".cp").append(html);
            $(".ll").css('visibility','visible');

        } else if (cha == 1) {
            var html = `
                <div class="ch-row ch-info-form shan">
                    <p class="flex2">项目选择:</p>
                    <div class="flex4">
                        <select name="class_a" class="class_a1 form-control">
                            {volist name="po" id="v"}
                            <option value="{$v.detailed_id}" <?php if($data["class_a"]==$v["detailed_title"]){?> selected="selected" <?php }?>>{$v.detailed_title}</option>\n
                            {/volist}
                        </select>
                        <select name="class_b" class="class_b1 form-control">
                            {volist name="po1" id="v"}
                            <option value="{$v.detailed_id}" <?php if($data["class_b"]==$v["detailed_title"]){?> selected="selected" <?php }?>>{$v.detailed_title}</option>\n
                            {/volist}
                        </select>
                    </div>
                </div>`
            $(".cp").append(html);
            $(".ll").css('visibility','visible');
        } else if (cha == 2) {
            var html = `
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">标题：</p>
                    <div class="flex2">
                        <input type="text" name="class_a" placeholder="请输入标题" class=" form-control" value="{$data.class_a}">
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">单位：</p>
                    <div class="flex2">
                        <select   name="companys" class="class_a3 form-control">
                        {volist name="g" id="v"}
                        <option value="{$v.title}"<?php if($data["company"]==$v["title"]){?> selected="selected" <?php }?>>{$v.title}</option>\n
                        {/volist}
                        </select>
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">标价：</p>
                    <div class="flex2">
                        <input type="number" name="un_Prices" placeholder="请输入标价" class="un_Price form-control" value="{$data.un_Price}">
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">备注：</p>
                    <div class="flex2">
                        <textarea name="qi_rmakes" class="form-control">{$data.qi_rmakes}</textarea>
                    </div>
                </div>`;
            $(".cp").append(html);
            $('.ll').css('visibility','hidden');
            $('.companys').css('display','none');
            $('.wei').css('display','none');
            $('.o').remove();
            $('#price_rule').html('');
        }
    }
    $(document).on("change", ".class_a1", function () {
        var detaileds_id = $(this).val();
        console.log(detaileds_id);
        $.post("{:url('index/order/detailed')}", {detaileds_id: detaileds_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var pris;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "' >" + data[i]['detailed_title'] + "</option>";
                    artificial = data[0]['artificial'];
                    dan = data[0]['titles'];
                    pris = data[0]['rmakes'];
                }
            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.class_b1').html(html);
            $('.dan1').val(artificial);
            $('.companys').val(dan);
            $('#price_rule').html(pris);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });
    });
    $(document).on("change", ".class_a2", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var price_rule;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['product_id'] + "' >" + data[i]['product_title'] + "</option>";
                    artificial = data[0]['prices'];
                    price_rule = data[0]['price_rules'];
                    dan = data[0]['titles'];
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }
            $('.companys').val(dan);
            $('.class_b').html(html);
            $('.dan1').val(artificial);
            $('#price_rule').html(price_rule);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".class_b", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan_dan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var price_rule;
            artificial = data['prices'];
            dan = data['titles'];
            price_rule = data['price_rules'];
            $('.companys').val(dan);
            $('#price_rule').html(price_rule);

            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".class_b1", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/detailed_dan')}", {detaileds_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var pris;
            artificial = data['artificial'];
            dan = data['titles'];
            pris = data['rmakes'];
            $('#price_rule').html(pris);
            $('.companys').val(dan);
            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });

    $('.fang').bind("change", function () {
        //向input输入框中赋值
        var chan = $('.chan').val();
        var companys = $('.dan1').val();
        var fang = $('.fang').val();
        if (chan == 2) {
            var un_Price = $('.un_Price').val();
            var num =((un_Price * 1000) * fang) / 1000 ;
            num = num.toFixed(2);
            $('.jia').val(num);

        } else {
            var num =((companys * 1000) * fang) / 1000 ;
            num = num.toFixed(2);
            $('.jia').val(num);

        }


    });
    $('.un_Price').bind("change", function () {
        //向input输入框中赋值
        $('.fang').val('');
        $('.jias').val('');
        $('.jia').val('');
    });
    /***
     *
     *
     * 提交代码
     * */
    $('.radius').click(function () {
        var src = "{:Url('index/order/edit2')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data: $('form').serializeArray(),
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index, layero) {
                        setTimeout("window.parent.location.reload()", 1);

                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });

</script>
</body>
</html>